{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 1.2. Getting started with exploratory data analysis in the Jupyter Notebook"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "import numpy as np\n",
    "import pandas as pd\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "url = (\"https://raw.githubusercontent.com/ipython-books/cookbook-2nd-data/master/bikes.csv\")"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "outputs": [],
   "source": [
    "df = pd.read_csv(url, index_col='Date', parse_dates=True, dayfirst=True)"
   ],
   "metadata": {
    "collapsed": false
   }
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "podoc": {
     "output_text": "Output"
    },
    "ExecuteTime": {
     "end_time": "2023-10-20T12:38:54.252286Z",
     "start_time": "2023-10-20T12:38:54.252151Z"
    }
   },
   "outputs": [],
   "source": [
    "df.head(2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "podoc": {
     "output_text": "Output"
    },
    "ExecuteTime": {
     "end_time": "2023-10-20T12:38:54.252844Z",
     "start_time": "2023-10-20T12:38:54.252378Z"
    }
   },
   "outputs": [],
   "source": [
    "df.describe()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "podoc": {
     "output_text": "<matplotlib.figure.Figure at 0x7fe6b43abc18>"
    },
    "ExecuteTime": {
     "end_time": "2023-10-20T12:38:54.253326Z",
     "start_time": "2023-10-20T12:38:54.252924Z"
    }
   },
   "outputs": [],
   "source": [
    "df[['Berri1', 'PierDup']].plot(figsize=(10, 6),\n",
    "                               style=['-', '--'],\n",
    "                               lw=2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "end_time": "2023-10-20T12:38:54.269039Z",
     "start_time": "2023-10-20T12:38:54.254689Z"
    }
   },
   "outputs": [],
   "source": [
    "df.index.weekday_name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "ExecuteTime": {
     "start_time": "2023-10-20T12:38:54.256399Z"
    }
   },
   "outputs": [],
   "source": [
    "df_week = df.groupby(df.index.weekday).sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "podoc": {
     "output_text": "Output"
    },
    "ExecuteTime": {
     "start_time": "2023-10-20T12:38:54.258045Z"
    }
   },
   "outputs": [],
   "source": [
    "df_week"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "podoc": {
     "output_text": "<matplotlib.figure.Figure at 0x8f03e48>"
    },
    "ExecuteTime": {
     "start_time": "2023-10-20T12:38:54.259382Z"
    }
   },
   "outputs": [],
   "source": [
    "fig, ax = plt.subplots(1, 1, figsize=(10, 8))\n",
    "df_week.plot(style='-o', lw=3, ax=ax)\n",
    "ax.set_xlabel('Weekday')\n",
    "# We replace the labels 0, 1, 2... by the weekday\n",
    "# names.\n",
    "ax.set_xticklabels(\n",
    "    ('Monday,Tuesday,Wednesday,Thursday,'\n",
    "     'Friday,Saturday,Sunday').split(','))\n",
    "ax.set_ylim(0)  # Set the bottom axis to 0."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {
    "podoc": {
     "output_text": "Rolling mean"
    },
    "ExecuteTime": {
     "start_time": "2023-10-20T12:38:54.260042Z"
    }
   },
   "outputs": [],
   "source": [
    "from ipywidgets import interact\n",
    "\n",
    "@interact\n",
    "def plot(n=(1, 30)):\n",
    "    fig, ax = plt.subplots(1, 1, figsize=(10, 8))\n",
    "    df['Berri1'].rolling(window=n).mean().plot(ax=ax)\n",
    "    ax.set_ylim(0, 7000)\n",
    "    plt.show()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "name": "python3",
   "language": "python",
   "display_name": "Python 3 (ipykernel)"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
